package _18_剑指OfferII;

import _18_剑指OfferII.datastrcute.TreeNode;

import java.util.HashSet;

public class _056_剑指OfferII二叉搜索树中两个节点之和 {


    public boolean findTarget(TreeNode root, int k) {
        HashSet<Integer> set = new HashSet<>();
        return traversTree(root, set, k);
    }

    private boolean traversTree(TreeNode root, HashSet<Integer> set, int k) {
        if (root == null) return false;
        if (set.contains(k - root.val)) return true;
        set.add(root.val);
        return traversTree(root.left, set, k) || traversTree(root.right, set, k);
    }


}
